function subCheck(){
	if($("#startDate").length > 0  && $("#endDate").length > 0){
		var startDate = $("#startDate").val();
		var endDate = $("#endDate").val();
		if(startDate == ""){
			alert("请选择开始时间!");
			return false;
		}
		if(endDate == ""){
			alert("请选择结束时间!");
			return false;
		}
		if(startDate > endDate){
			alert(startDate);
			alert(endDate);
			alert("开始时间不能大于结束时间！");
			return false;
		}
		
		var isMonthSearch = $("#isMonthSearch").val();
		if(isMonthSearch == 0 ){
			startDate = startDate.substring(0,startDate.lastIndexOf('-'));
			endDate = endDate.substring(0,endDate.lastIndexOf('-'));
			if(startDate != endDate){
				alert("本报表不支持跨月查询!");
				return false;
			}
		}
		
	}

	if($("#searchDate").length > 0 ){
		var searchDate = $("#searchDate").val();
		if(searchDate == ""){
			alert("请选择查询时间!");
			return false;
		}
	}
    return true;
}

function sub(){
	var formname = $("#formname").val();
	$("#"+formname).submit();
}

$(function(){
	$("#tosearch").click(function(){
		$("#ordervalue").val("");
		$("#ordertype").val("");
    	$("#down").val(0);
		if(subCheck()){
			sub();
		}
	});
});


$(function(){
	$("#suborder").click(function(){
    	$("#down").val(0);
		
		var ordervalue = $("#ordervalue").val();
		var ordertype = $("#ordertype").val();
		if("" == ordervalue || "" == ordertype){
			alert("排序条件不完整，请选择！");
			return false;
		}else{
			if(subCheck()){
				sub();
			}
		}
	});
});

		
$(function(){
	$("#download").click(function(){
		$("#down").val(1);
		if(subCheck()){
			sub();
		}
	});
});

$(function(){
   $("#dpCateOne").change(function(){
      var cate1 = $("#dpCateOne").val();
      var channelName = $("#dpChannelName").val();
      if(cate1 != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/discate",
        data:{"cate1":cate1,"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateTwoList = "";
    		  cateTwoList = "<option value=''>全部</option>";
              $.each(data.discateListTwo, function(i, obj) {
                 cateTwoList = cateTwoList + "<option value='"+obj.cate2+"'>"+obj.cate2+"</option>";
              });
              $("#dpCateTwo").empty().append(cateTwoList);
			  
			  var cateThreeList = "<option value=''>全部</option>";
			  $("#dpCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#dpCateTwo").empty().append(cateList);
		  $("#dpCateThree").empty().append(cateList);
	  }
    });
});

$(function(){
   $("#dpCateTwo").change(function(){
      var cate1 = $("#dpCateOne").val();
	  var cate2 = $("#dpCateTwo").val();
	  var channelName = $("#dpChannelName").val();
      if(cate1 != "" && cate2 != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/discate",
        data:{"cate1":cate1,"cate2":cate2,"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateThreeList = "";
    		  cateThreeList = "<option value=''>全部</option>";
              $.each(data.discateListThree, function(i, obj) {
                 cateThreeList = cateThreeList + "<option value='"+obj.cate3+"'>"+obj.cate3+"</option>";
              });
              $("#dpCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#dpCateThree").empty().append(cateList);
	  }
    });
});



$(function(){
   $("#bcCateOne").change(function(){
      var cate1 = $("#bcCateOne").val();
      var channelName = $("#bcChannelName").val();
      if(cate1 != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/belongcate",
        data:{"cate1":cate1,"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateTwoList = "";
    		  cateTwoList = "<option value=''>全部</option>";
              $.each(data.belongcateListTwo, function(i, obj) {
                 cateTwoList = cateTwoList + "<option value='"+obj.cate2+"'>"+obj.cate2+"</option>";
              });
              $("#bcCateTwo").empty().append(cateTwoList);
			  
			  var cateThreeList = "<option value=''>全部</option>";
			  $("#bcCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#bcCateTwo").empty().append(cateList);
		  $("#bcCateThree").empty().append(cateList);
	  }
    });
});

$(function(){
   $("#bcCateTwo").change(function(){
      var cate1 = $("#bcCateOne").val();
	  var cate2 = $("#bcCateTwo").val();
	  var channelName = $("#channelName").val();
	  
      if(cate1 != "" && cate2 != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/belongcate",
        data:{"cate1":cate1,"cate2":cate2,"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateThreeList = "";
    		  cateThreeList = "<option value=''>全部</option>";
              $.each(data.belongcateListThree, function(i, obj) {
                 cateThreeList = cateThreeList + "<option value='"+obj.cate3+"'>"+obj.cate3+"</option>";
              });
              $("#bcCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#bcCateThree").empty().append(cateList);
	  }
    });
});

	function addchvalues(value){
			var chartvalues = $("#chartvalues").val();
			var fs = chartvalues.split(",");
			var newfs ="";
			var flag = false;
			for(var i=0;i<fs.length;i++){
				var f = fs[i];
				if(f!=""){
    				if(f == value){
    				  flag = true;
    				  continue;
    				}
    				newfs = newfs + f+",";
				}
			}
			if(!flag){
				newfs = newfs + value+",";
			}
			$("#chartvalues").val(newfs);
		}
		
		
 $(function(){$("#graphshow").click(function(){
		 		var chartvalues = $("#chartvalues").val();
		 		if("" == chartvalues){
					alert("请选择绘图指标！");
					return false;
				}
				
				if(chartvalues.lastIndexOf(",")+1 == chartvalues.length){
					chartvalues = chartvalues.substring(0,chartvalues.lastIndexOf(","));
				}
				
				var fs = chartvalues.split(",");
				if(fs.length > 10){
					alert("最多只能选择10个指标进行绘图！");
					return false;
				}
				
				var formname = $("#formname").val();
				var pathId  = $("#pathId").val();
				$("#chartvalues").val(chartvalues);
				$("#chartType").val(1);
            	jQuery.ajax({
        			url:"/intreport/chartsearch/"+pathId,
            		type:"post",
            		async:true,
					dataType:"json",
            		data:$('#'+formname).serialize(), 
            		success:function(cc){
						var data = cc.result;
                		if(data == "error" || data == ""){
							alert("error!");
						}else{
						  var chart ;
						  if(data.indexOf("LINEDY") > -1){
							chart = new FusionCharts("/image/swf/fusionChartsCracker.swf?chartUrl=/image/swf/MSColumn3DLineDY.swf", "ChartId", "970", "350", "0", "0");
						  }else if(data.indexOf("LINE2D") > -1){
							chart = new FusionCharts("/image/swf/fusionChartsCracker.swf?chartUrl=/image/swf/MSLine.swf", "ChartId", "970", "350", "0", "0");
						  }
						  var xml = data.substring(data.indexOf(":")+1);
						  chart.setDataXML(xml);	
					      chart.render("chartdiv");
						}
            		}
            	});
        	 })
})



 $(function(){$("#pieshow").click(function(){
		 		var chartvalues = $("#chartvalues").val();
		 		if("" == chartvalues){
					alert("请选择绘图指标！");
					return false;
				}
				
				if(chartvalues.lastIndexOf(",")+1 == chartvalues.length){
					chartvalues = chartvalues.substring(0,chartvalues.lastIndexOf(","));
				}
				
				var fs = chartvalues.split(",");
				if(fs.length > 1){
					alert("最多只能选择1个指标进行绘图！");
					return false;
				}
				
				var formname = $("#formname").val();
				var pathId  = $("#pathId").val();
				$("#chartvalues").val(chartvalues);
				$("#chartType").val(2);
            	jQuery.ajax({
        			url:"/intreport/chartsearch/"+pathId,
            		type:"post",
            		async:true,
					dataType:"json",
            		data:$('#'+formname).serialize(), 
            		success:function(cc){
						var data = cc.result;
                		if(data == "error" || data == ""){
							alert("error!");
						}else{
						  var chart ;
						  var chart = new FusionCharts("/image/swf/fusionChartsCracker.swf?chartUrl=/image/swf/Pie3D.swf", "ChartId", "800", "500", "0", "0");
						  var xml = data;
						  chart.setDataXML(xml);	
					      chart.render("chartdiv");
						}
            		}
            	});
        	 })
})


function formatDate(oldDate) { 
	var dates = oldDate.split("-");
	var newDate = dates[0];
	
	for(var i = 1;i < dates.length; i++){
		var temp = dates[i];
		if(temp < 10){  
			newDate = newDate+"-0"+temp
		}else{
			newDate = newDate+"-"+temp
		}
	}
	
	return newDate;
}  

function selectDate(dayNum){
    var endDate = new Date();
	var startDate = "";
	if(dayNum == "-7"){
		var uom = new Date(new Date()-0+(-7)*86400000);
		startDate = uom.getFullYear() + "-" +  (uom.getMonth()+1) + "-" + uom.getDate();
	}else if(dayNum == "-1m"){
		if(endDate.getMonth() == 0){
			startDate = endDate.getFullYear()-1 + "-12-" + endDate.getDate();
		}else{
			startDate = endDate.getFullYear() + "-" + endDate.getMonth() + "-" + endDate.getDate();
		}
	}

    endDate = endDate.getFullYear() + "-" +  (endDate.getMonth()+1) + "-" + endDate.getDate();
	
	startDate = formatDate (startDate);
	endDate = formatDate (endDate);
	
	$("#endDate").val(endDate);
	$("#startDate").val(startDate);
}


$(function(){
   $("#dpChannelName").change(function(){
      var channelName = $("#dpChannelName").val();
      if(channelName != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/discate",
        data:{"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateOneList = "";
    		  cateOneList = "<option value=''>全部</option>";
              $.each(data.discateListOne, function(i, obj) {
                 cateOneList = cateOneList + "<option value='"+obj.cate1+"'>"+obj.cate1+"</option>";
              });
              $("#dpCateOne").empty().append(cateOneList);
			  
			  var cateThreeList = "<option value=''>全部</option>";
			  $("#dpCateTwo").empty().append(cateThreeList);
			  $("#dpCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#dpCateOne").empty().append(cateList);
		  $("#dpCateTwo").empty().append(cateList);
		  $("#dpCateThree").empty().append(cateList);
	  }
    });
});


$(function(){
   $("#bcChannelName").change(function(){
      var channelName = $("#bcChannelName").val();
      if(channelName != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/belongcate",
        data:{"channelName":channelName},
        success:function(data){
           if(data!="" && data.result =="right"){
              var cateOneList = "";
    		  cateOneList = "<option value=''>全部</option>";
              $.each(data.belongcateListOne, function(i, obj) {
                 cateOneList = cateOneList + "<option value='"+obj.cate1+"'>"+obj.cate1+"</option>";
              });
              $("#bcCateOne").empty().append(cateOneList);
			  
			  var cateThreeList = "<option value=''>全部</option>";
			  $("#bcCateTwo").empty().append(cateThreeList);
			  $("#bcCateThree").empty().append(cateThreeList);
           }else{
		   	  alert("error!");
		   }
        }
   	  });
      }else{
	 	  var cateList = "<option value=''>全部</option>";
		  $("#bcCateOne").empty().append(cateList);
		  $("#bcCateTwo").empty().append(cateList);
		  $("#bcCateThree").empty().append(cateList);
	  }
    });
});


function addgroupby(value){
	var functions = $("#groupBy").val();
	var fs = functions.split(",");
	var newfs ="";
	var flag = false;
	for(var i=0;i<fs.length;i++){
		var f = fs[i];
		if(f!=""){
    	   if(f == value){
    			flag = true;
    			continue;
    		}
    		newfs = newfs + f+",";
		}
	}
	if(!flag){
		newfs = newfs + value+",";
	}
	functions = newfs;
	if(functions.lastIndexOf(",")+1 == functions.length){
		functions = functions.substring(0,functions.lastIndexOf(","));
	}
	$("#groupBy").val(functions);
	
	if(functions.indexOf("stat_date") < 0 && functions.indexOf("statDate")  <0){
		$("#dayRatio").attr("checked",false);
		$("#weekRatio").attr("checked",false);
		$("#dayRatio").attr("disabled",true);
		$("#weekRatio").attr("disabled",true);
		$("#hasComp").val("");
	}else{
		$("#dayRatio").removeAttr("disabled");
		$("#weekRatio").removeAttr("disabled");
	}
}

function checkgroupby(){
	if($("#groupBy").length == 0)
		return;
	var groupBy = $("#groupBy").val();
	var fs = groupBy.split(",");
	for(var i=0;i<fs.length;i++){
		var f = fs[i];
		var count = f.split(":")[0];
		$("#selectgb"+count).attr("checked",true);
	}
	if(groupBy.indexOf("stat_date") < 0 && groupBy.indexOf("statDate") < 0 && groupBy.indexOf("vDate") < 0){
		$("#dayRatio").attr("checked",false);
		$("#weekRatio").attr("checked",false);
		$("#dayRatio").attr("disabled",true);
		$("#weekRatio").attr("disabled",true);
		$("#hasComp").val("");
	}else{
		$("#dayRatio").removeAttr("disabled");
		$("#weekRatio").removeAttr("disabled");
	}
}

		
$(function(){
	$("div[name='tab']").each(function(){
		checkSelectAll(this);
	});
});

//标签悬浮关闭
//$(function(){
//	if($("#ui-tab").length > 0){
//			var tabs = $("#ui-tab").tabs().tabs('tabs');
//			for(var i=0; i<tabs.length; i++){
//				tabs[i].panel('options').tab.unbind().bind('mouseenter',{index:i},function(e){
//					$('#ui-tab').tabs('select', e.data.index);
//				});
//			}
//	}
//});
//检查是否应该全选
function checkSelectAll(tabDiv){
		var allCheck=$(tabDiv).find(":checkbox[name='selectAllCol']");
		var isAll=true;
		$(tabDiv).find(":checkbox[name='selectCol']").each(function(){
			if(!$(this).is(':checked')){
				isAll=false;
				return false;
			}
		});
		if(isAll)
			allCheck.prop('checked',true);
}

//全选
function selectAllCols(cell){
	var isCheck = $(cell).is(':checked');
	var thisTab = $(cell).closest('[name="tab"]');
	thisTab.find('[name="selectCol"]').prop('checked',isCheck);
	setColsSelect();
}
	
//选择一个	
function addSelect(cell){
	var isCheck = $(cell).is(':checked');
	if(!isCheck)
		$(cell).closest('[name="tab"]').find('#selectAllCol').prop('checked',isCheck);
	checkSelectAll($(cell).closest("div[name='tab']"));//检查是否应该全选
	setColsSelect(); 
}
function removeSelect(){
	$("div[name='tab']").find(":checkbox").prop('checked',false);
	$("#colsSelect").val("");
}
//设置所选指标选项值
function setColsSelect(){
	var cols = "";
	var checkboxs = document.getElementsByName("selectCol");
	for (var i = 0;i<checkboxs.length; i++) {
 		 var e = checkboxs[i];
		 if(e.checked){
    	 	cols = cols + e.value + ",";
    	 }
 	}
	$("#colsSelect").val(cols);
}


function dataCompare(){
	var cols = "";
	var checkboxs = document.getElementsByName("dcc");
	for (var i = 0;i<checkboxs.length; i++) {
 		 var e = checkboxs[i];
		 if(e.checked){
    	 	cols = cols + e.value + ",";
    	 }
 	}
	$("#compareSelect").val(cols);
}


   function sendFre(id){
		var value = "";
    	if(id == 1){
			value = "day";
		}else if(id == 2){
			value = "week";
		}
		$("#freValue").val(value);
    }
	
	
$(function(){
   $("#subMail").click(function(){
   	
   	  var ads = $("#emailAds").val();
   	  if("" == ads){
   	  	alert("订阅地址不能为空");
   	  	return false;
   	  }else{
   	  	var adsp = ads.split('/');
   	  	for(var i=0;i<adsp.length;i++){
   	  		if(adsp[i].indexOf('@58.com') == -1){
   	  			alert("邮箱只可为公司企业邮箱");
   	  			return false;
   	  		}
   	  	}
   	  }
   	
 	  var freValue = $("#freValue").val();
	  if("" == freValue){
	  	alert("请选择发送频率!");
		return false;
	  }else{
      	jQuery.ajax({
            type:"POST",
            dataType:"json",
            async:true,
            url:"/irtools/reportSubMail",
            data:{"emailAds":$("#emailAds").val(),"freValue":freValue,"subName":$("#subName").val(),"reportId":$("#reportId").val()},
            success:function(data){
               if(data.result == "success"){
			   		alert("订阅成功！");
			   }else{
			 		alert("订阅失败，请重新订阅！");
			   }
            }
       	 });
	  }
    });
});


function addComp(value){
	var hasComp =	$("#hasComp").val();
	var fs = hasComp.split(",");
	var newfs ="";
	var flag = false;
	for(var i=0;i<fs.length;i++){
		var f = fs[i];
		if(f!=""){
    	   if(f == value){
    			flag = true;
    			continue;
    		}
    		newfs = newfs + f+",";
		}
	}
	if(!flag){
		newfs = newfs + value+",";
	}
	hasComp = newfs;
	if(hasComp.lastIndexOf(",")+1 == hasComp.length){
		hasComp = hasComp.substring(0,hasComp.lastIndexOf(","));
	}
	$("#hasComp").val(hasComp);
};

$(function(){
	$("#dayRatio,#weekRatio").click(function(){
		if($(this).attr("disabled")==true)
			return;
		else
			addComp($(this).attr("id"));
	});
});

function sendInfo(url){
	$.ajax({ 
        url: "/irtools/visitrecord", 
        type: 'GET',    
        async:true,
        dataType: 'text',     
        data: "&url="+encodeURIComponent(url), 
        cache:false,
        success: function(json){
		}
});
}
sendInfo(document.URL);




var zhongxiao=['菏泽','临汾','枣庄','晋城','张家口','大同','濮阳','周口','滨州','绥化','丹东','揭阳','盘锦','承德','葫芦岛','宜宾','运城',
			'长治','晋中','四平','遂宁','清远','鸡西','玉溪','宿迁','白城','朝阳','驻马店','达州','辽阳','本溪','茂名','贵港','安康','萍乡',
			'通辽','铁岭','庆阳','乌海','鄂州','随州','红河','韶关','益阳','资阳','广安','抚州','毕节','伊春','咸宁','黑河','梅州','贺州','双鸭山',
			'六盘水','潮州','白银','兴安盟','巴中','武威','黔东南','安顺','延安','锡林郭勒','黔南','楚雄','中卫','铜川','张家界','阿克苏','平凉',
			'河池','张掖','商洛','雅安','文山','临沧','昭通','汕尾','哈密','铜仁','白山','定西','来宾','防城港','喀什','大兴安岭','仙桃','酒泉','七台河',
			'固原','海拉尔','金昌','潜江','百色','普洱','云浮','保山','湘西','阿拉善盟','那曲','甘孜','陇南','张北','黔西南','临夏','天门','西双版纳',
			'嘉峪关','博尔塔拉','崇左','甘南','阿坝','海西','迪庆','怒江','神农架','昌都','果洛','黄南','海南','海东','香港','林芝','海北','五家渠','山南',
			'三沙','和田','玉树','吐鲁番','台湾','澳门','阿里','阿拉尔','五指山','日喀则','克孜勒苏','图木舒克','马来西亚','新加坡','泰国','衢州','阜新',
			'汉中','鹤壁','怀化','济源','郴州','娄底','莱芜','攀枝花','三门峡','大理','丽江','邵阳','孝感','阳泉','通化','德宏','梧州','钦州','忻州','朔州','吴忠',
			'呼伦贝尔','吕梁','河源','广元','巴彦淖尔市','辽源','丽水','玉林','乌兰察布','景德镇','阳江','永州','眉山','鹤岗','凉山','恩施'];
var zhiying=['北京', '成都', '重庆', '石家庄', '济南', '青岛','南京', '杭州', '苏州', '无锡', '合肥',	'武汉', '郑州', '长沙', '福州', 
				'厦门', '南宁', '哈尔滨', '长春', '太原', '大连', '沈阳','上海', '天津', '广州', '深圳', '东莞'];
			

function setCityBatch(id,cityArr,state){
	if(state == 'checked'){
		$("input[name='multiselect_"+id+"']:checkbox").filter(function (index){
			return $.inArray($(this).val(),cityArr) >= 0;
		}).prop("checked", true);
	}else{
		$("input[name='multiselect_"+id+"']:checkbox").filter(function (index){
			return $.inArray($(this).val(),cityArr) >= 0;
		}).prop("checked", false);
	}
};
function uncheckCity(id,city){
	if($.inArray(city,zhongxiao) >= 0)
		$("input[name='multiselect_"+id+"']:checkbox[value='zscitys']").prop("checked", false);
	if($.inArray(city,zhiying) >= 0)
		$("input[name='multiselect_"+id+"']:checkbox[value='zycitys']").prop("checked", false);
}
				
function changeOthers(value,state){
	if(state == 'enable')
		$("input[name='multiselect_cityOne']:checkbox[value!='"+value+"']").prop("checked", false).prop("disabled", false);
	else
		$("input[name='multiselect_cityOne']:checkbox[value!='"+value+"']").prop("checked", false).prop("disabled", true);
};

function changeSpecial(state){
	if(state == 'enable'){
		$("input[name='multiselect_cityOne']:checkbox[value='zscitys']").prop("checked", false).prop("disabled", false);
		$("input[name='multiselect_cityOne']:checkbox[value='zycitys']").prop("checked", false).prop("disabled", false);
	}
	else{
		$("input[name='multiselect_cityOne']:checkbox[value='zscitys']").prop("checked", false).prop("disabled", true);
		$("input[name='multiselect_cityOne']:checkbox[value='zycitys']").prop("checked", false).prop("disabled", true);
	}
};


function removeCityTwo(IDSuffix){
		  $("#cityTwo_"+IDSuffix).empty();
		  $("#cityThree_"+IDSuffix).empty();
		  
		  $("#cityTwo_"+IDSuffix).multiselect('refresh');
		  $("#cityThree_"+IDSuffix).multiselect('refresh');
		  
		  $("#"+IDSuffix+"CityTwo").val('');
		  $("#"+IDSuffix+"CityThree").val('');
}

function removeCityThree(IDSuffix){
		  $("#cityThree_"+IDSuffix).empty();
		  $("#cityThree_"+IDSuffix).multiselect('refresh');
		  $("#"+IDSuffix+"CityThree").val('');
}

function changeCityTwo(city1,type){
	var reqUrl = '';
	var IDSuffix = 'dl';
	var listName='';
	if(type == "dl"){
		reqUrl = "/irtools/displaylocal";
		listName="disCityListTwo";
	}
	else if(type == "bl"){
		reqUrl = "/irtools/belongcity";
		IDSuffix="bl";
		listName="belongCityListTwo";
	}
	if(city1 != "" && city1 !="zycitys" && city1 !="zscitys" ){
      	jQuery.ajax({
      		type:"post",
        	dataType:"json",
        	async:true,
        	url:reqUrl,
        	data:{"city1":city1},
        	success:function(data){
          	if(data!="" && data.result =="right"){
             	var cityTwoList = "";
              	$.each(data[listName], function(i, obj) {
                 	cityTwoList = cityTwoList + "<option value='"+obj.localName+"'>"+obj.localName+"</option>";
              	});
              	$("#cityTwo_"+IDSuffix).empty().append(cityTwoList);
			 	$("#cityThree_"+IDSuffix).empty();
			  	$("#cityTwo_"+IDSuffix).multiselect('refresh');
			   	$("#cityThree_"+IDSuffix).multiselect('refresh');
			   	$("#"+IDSuffix+"CityTwo").val('');
			   	$("#"+IDSuffix+"CityThree").val('');
           }else{
		   	  alert("error!");
		   }
        }
   	  });
     }else{
	 	  removeCityTwo(IDSuffix);
	  }
}

function changeCityThree(city1,city2,type){
	var localVar=String(city1);
	var reqUrl = '';
	var IDSuffix = 'dl';
	var listName='';
	if(type =="dl"){
		reqUrl= "/irtools/displaylocal";
		listName='disCityListThree';	
	}
	else if(type == "bl"){
		reqUrl= "/irtools/belongcity";
		IDSuffix="bl";
		listName='belongCityListThree';
	}
	if(localVar != "" && city2 != ""){
      	jQuery.ajax({
       		type:"post",
        	dataType:"json",
        	async:true,
        	url:reqUrl,
        	data:{"city2":city2,"city1":localVar},
        	success:function(data){
           	if(data!="" && data.result =="right"){
              var cityThreeList = "";
              $.each(data[listName], function(i, obj) {
                 cityThreeList = cityThreeList + "<option value='"+obj.localName+"'>"+obj.localName+"</option>";
              });
             $("#cityThree_"+IDSuffix).empty().append(cityThreeList);
             $("#cityThree_"+IDSuffix).multiselect('refresh');
             $("#"+IDSuffix+"CityThree").val('');
           }else{
		   	  alert("error!");
		   }
        }
   	  });
     }else{
		removeCityThree(IDSuffix);
	 }
}


$(function(){
   	$("#cityThree_dl").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			if($("input[name='multiselect_cityThree_dl']:checkbox:checked").length == 0){
				$("#dlCityThree").val('');
			}   		
   		},
   		checkAll: function(){},
		uncheckAll: function(){
            $("#dlCityThree").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var three='';
            var idcs=checkedItems.map(function(element){
            	if(numChecked == 1){
            		three = $(element).val();
            	}
            	return "'"+element.value+"'"; 
            }).join(',');
              $("#dlCityThree").val(idcs);
             if(numChecked == numTotal && numTotal > 1){
                     ("#dlCityThree").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? three : numChecked + ' of ' + numTotal + ' citys';
		}
   });
    $("#cityThree_dl").multiselect('refresh');
});



$(function(){
   	$("#cityTwo_dl").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			var checkedItems=$("input[name='multiselect_cityTwo_dl']:checkbox:checked");
			if(checkedItems.length == 0){
				$("#dlCityTwo").val('');
				removeCityThree("dl");
			}else if(checkedItems.length == 1){
				changeCityThree($("#cityOne_dl").val(),checkedItems.get(0).value,"dl");
			}
   		},
   		checkAll: function(){
			var checkedItems=$("input[name='multiselect_cityTwo_dl']:checkbox:checked");
			if(checkedItems.length == 1){
				changeCityThree($("#cityOne_dl").val(),checkedItems.get(0).value,"dl");
			}   		
   		},
		uncheckAll: function(){
			removeCityThree("dl");
            $("#dlCityTwo").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var two='';
            var idcs=checkedItems.map(function(element){
            	if(numChecked == 1){
            		two = $(element).val();
            	}
            	return "'"+element.value+"'"; 
            }).join(',');
            if(numChecked > 1){
            	removeCityThree("dl");
            }
              $("#dlCityTwo").val(idcs);
             if(numChecked == numTotal  && numTotal > 1){
                     $("#dlCityTwo").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? two : numChecked + ' of ' + numTotal + ' citys';
		}
   });
});

$(function(){
   	$("#cityOne_dl").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			if(ui.checked){
				if(ui.value == 'zycitys'){
					setCityBatch("cityOne_dl",zhiying,'checked');
				}else if(ui.value == 'zscitys'){
					setCityBatch("cityOne_dl",zhongxiao,'checked');
				}
			}else{
			 	if(ui.value == 'zycitys'){
					setCityBatch("cityOne_dl",zhiying,'unchecked');
				}else if(ui.value == 'zscitys'){
					setCityBatch("cityOne_dl",zhongxiao,'unchecked');
				}else{
					uncheckCity("cityOne_dl",ui.value);
				}
			}
			var checkedItems=$("input[name='multiselect_cityOne_dl']:checkbox:checked");
			if(checkedItems.length == 0){
				$("#dlCityOne").val('');
				removeCityTwo("dl");
			}else if(checkedItems.length == 1){
				changeCityTwo(checkedItems.get(0).value,"dl");
			}
   		},
   		checkAll: function(){
			var checkedItems=$("input[name='multiselect_cityOne_dl']:checkbox:checked");
			if(checkedItems.length == 1){
				changeCityTwo(checkedItems.get(0).value,"dl");
			}   		
   		},
		uncheckAll: function(){
			removeCityTwo("dl");
            $("#dlCityOne").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var realNumTotal = numTotal-2;
			var realNumChecked = numChecked;
			var one='';
            var idcs=$.map(checkedItems,function(element){
            	one = element.value;
            	if(one == 'zycitys' || one == 'zscitys'){
            		realNumChecked--;
            	}
            	return "'"+element.value+"'"; 
            }).join(',');
            if(numChecked > 1){
            	removeCityTwo("dl");
            }
            $("#dlCityOne").val(idcs);

            if(realNumChecked == realNumTotal  && realNumTotal > 1){
                     $("#dlCityOne").val('');
                     return "全部";
             }
			return (realNumChecked <= 1) ? one : realNumChecked + ' of ' + realNumTotal + ' citys';
		}
   });
});


$(function(){
   	$("#cityThree_bl").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			if($("input[name='multiselect_cityThree_bl']:checkbox:checked").length == 0){
				$("#blCityThree").val('');
			}   		
   		},
   		checkAll: function(){},
		uncheckAll: function(){
            $("#blCityThree").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var three='';
            var idcs=checkedItems.map(function(element){
            	if(numChecked == 1){
            		three = $(element).val();
            	}
            	return "'"+element.value+"'"; 
            }).join(',');
              $("#blCityThree").val(idcs);
             if(numChecked == numTotal){
                     ("#blCityThree").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? three : numChecked + ' of ' + numTotal + ' citys';
		}
   });
    $("#cityThree").multiselect('refresh');
});



$(function(){
   	$("#cityTwo_bl").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			var checkedItems=$("input[name='multiselect_cityTwo_bl']:checkbox:checked");
			if(checkedItems.length == 0){
				$("#dlCityTwo").val('');
				removeCityThree("bl");
			}else if(checkedItems.length == 1){
				changeCityThree($("#cityOne_bl").val(),checkedItems.get(0).value,"bl");
			}
   		},
   		checkAll: function(){
			var checkedItems=$("input[name='multiselect_cityTwo_bl']:checkbox:checked");
			if(checkedItems.length == 1){
				changeCityThree($("#cityOne_bl").val(),checkedItems.get(0).value,"bl");
			}   		
   		},
		uncheckAll: function(){
			removeCityThree("bl");
            $("#blCityTwo").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var two='';
            var idcs=checkedItems.map(function(element){
            	if(numChecked == 1){
            		two = $(element).val();
            	}
            	return "'"+element.value+"'"; 
            }).join(',');
            if(numChecked > 1){
            	removeCityThree("bl");
            }
              $("#blCityTwo").val(idcs);
             if(numChecked == numTotal  && numTotal > 1){
                     $("#blCityTwo").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? two : numChecked + ' of ' + numTotal + ' citys';
		}
   });
});


$(function(){
   	$("#cityOne_bl").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			if(ui.checked){
				if(ui.value == 'zycitys'){
					setCityBatch("cityOne_bl",zhiying,'checked');
				}else if(ui.value == 'zscitys'){
					setCityBatch("cityOne_bl",zhongxiao,'checked');
				}
			}else{
			 	if(ui.value == 'zycitys'){
					setCityBatch("cityOne_bl",zhiying,'unchecked');
				}else if(ui.value == 'zscitys'){
					setCityBatch("cityOne_bl",zhongxiao,'unchecked');
				}else{
					uncheckCity("cityOne_bl",ui.value);
				}
			}
			var checkedItems=$("input[name='multiselect_cityOne_bl']:checkbox:checked");
			if(checkedItems.length == 0){
				$("#blCityOne").val('');
				removeCityTwo("bl");
			}else if(checkedItems.length == 1){
				changeCityTwo(checkedItems.get(0).value,"bl");
			}
   		},
   		checkAll: function(){
			var checkedItems=$("input[name='multiselect_cityOne_bl']:checkbox:checked");
			if(checkedItems.length == 1){
				changeCityTwo(checkedItems.get(0).value,"bl");
			}   		
   		},
		uncheckAll: function(){
			removeCityTwo("bl");
            $("#blCityOne").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var realNumTotal = numTotal-2;
			var realNumChecked = numChecked;
			var one='';
            var idcs=$.map(checkedItems,function(element){
            	one = element.value;
            	if(one == 'zycitys' || one == 'zscitys'){
            		realNumChecked--;
            	}
            	return "'"+element.value+"'"; 
            }).join(',');
            if(numChecked > 1){
            	removeCityTwo("bl");
            }
            $("#blCityOne").val(idcs);

            if(realNumChecked == realNumTotal  && realNumTotal > 1){
                     $("#blCityOne").val('');
                     return "全部";
             }
			return (realNumChecked <= 1) ? one : realNumChecked + ' of ' + realNumTotal + ' citys';
		}
   });
});


$(function(){
   	$("#city1").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			if(ui.checked){
				if(ui.value == 'zycitys'){
					setCityBatch("city1",zhiying,'checked');
				}else if(ui.value == 'zscitys'){
					setCityBatch("city1",zhongxiao,'checked');
				}
			}else{
			 	if(ui.value == 'zycitys'){
					setCityBatch("city1",zhiying,'unchecked');
				}else if(ui.value == 'zscitys'){
					setCityBatch("city1",zhongxiao,'unchecked');
				}else{
					uncheckCity("city1",ui.value);
				}
			}
			var checkedItems=$("input[name='multiselect_city1']:checkbox:checked");
			if(checkedItems.length == 0){
				$("#city").val('');
			}
   		},
   		checkAll: function(){},
		uncheckAll: function(){
            $("#city").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var realNumTotal = numTotal-2;
			var realNumChecked = numChecked;
			var one='';
            var idcs=$.map(checkedItems,function(element){
            	one = element.value;
            	if(one == 'zycitys' || one == 'zscitys'){
            		realNumChecked--;
            	}
            	return "'"+element.value+"'"; 
            }).join(',');
            $("#city").val(idcs);
            if(realNumChecked == realNumTotal){
                     $("#city").val('');
                     return "全部";
             }
			return (realNumChecked <= 1) ? one : realNumChecked + ' of ' + realNumTotal + ' citys';
		}
   });
    $("#city1").multiselect('refresh');
});






function changeInfoSourceName(type,platform){
	var localVar = String(platform);
	if(type == 'add' && localVar != ""){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/infosourceSearch",
        data:{"infoPlatform":localVar},
        success:function(data){
           if(data!="" && data.result =="right"){
          	  var sourceList = '';
              $.each(data.infoSourceList, function(i, obj) {
                 sourceList = sourceList + "<option value='"+obj.sourceName+"' title='"+obj.sourceName+"'>"+obj.sourceName+"</option>";
              });
              $("#sourceId_info").empty().append(sourceList);
               $("#sourceId_info").multiselect('refresh');
               $("#infoSourceName").val('');
           }else{
		   	  alert("error!");
		   }
        }
   	  });
	}else if(type == 'remove'){
		$("#sourceId_info").empty();
		$("#sourceId_info").multiselect('refresh');
		$("#infoSourceName").val('');
	}
}

$(function(){
   	$("#sourceId_info").multiselect({
		height:300,
		minWidth:140,    	
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			var checkedItems=$("input[name='multiselect_sourceId_info']:checkbox:checked");
			if(checkedItems.length == 0){
				$("#infoSourceName").val('');
			}
   		},
   		checkAll: function(){},
		uncheckAll: function(){
            $("#infoSourceName").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var one='';
            var idcs=$.map(checkedItems,function(element){
            	one = element.title;
            	return "'"+element.value+"'"; 
            }).join(',');
            $("#infoSourceName").val(idcs);
            if(numChecked == numTotal && numTotal > 1){
                     $("#infoSourceName").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? one : numChecked + ' of ' + numTotal + ' types';
		}
   });
});

$(function(){
   	$("#platform_info").multiselect({
		height:300,
		minWidth:140,    	
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			var checkedItems=$("input[name='multiselect_platform_info']:checkbox:checked");
			if(checkedItems.length == 0){
				changeInfoSourceName("remove");
				$("#infoPlatform").val('');
			}else if(checkedItems.length == 1){
				changeInfoSourceName('add',checkedItems.get(0).value);
			}
   		},
   		checkAll: function(){
			var checkedItems=$("input[name='multiselect_platform_info']:checkbox:checked");
			if(checkedItems.length == 1){
				changeInfoSourceName('add',checkedItems.get(0).value);
			}   		
   		},
		uncheckAll: function(){
			changeInfoSourceName("remove");
            $("#infoPlatform").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var one='';
            var idcs=$.map(checkedItems,function(element){
            	one = element.title;
            	return "'"+element.value+"'"; 
            }).join(',');
            if(numChecked > 1){
            	changeInfoSourceName("remove");
            }
            $("#infoPlatform").val(idcs);
            if(numChecked == numTotal  && numTotal > 1){
                     $("#infoPlatform").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? one : numChecked + ' of ' + numTotal + ' types';
		}
   });
});









function removeSourceTwo(){
		  $("#sourceTwo").empty();
		  $("#sourceThree").empty();
		  
		  $("#sourceTwo").multiselect('refresh');
		  $("#sourceThree").multiselect('refresh');
		  
		  $("#flowSourceTwo").val('');
		  $("#flowSourceThree").val('');
}

function removeSourceThree(){
		  $("#sourceThree").empty();
		  $("#sourceThree").multiselect('refresh');
		  $("#flowSourceThree").val('');
}


function changeSourceTwo(source1){
	if(source1 != "" ){
      	jQuery.ajax({
        type:"post",
        dataType:"json",
        async:true,
        url:"/irtools/flowsourcesearch",
        data:{"source1":source1},
        success:function(data){
           if(data!="" && data.result =="right"){
              	var cateTwoList = "";
              	$.each(data.flowSourceListTwo, function(i, obj) {
                cateTwoList = cateTwoList + "<option value='"+obj.source2+"' title='"+obj.source2_name+"'>"+obj.source2_name+"</option>";
             });
             $("#sourceTwo").empty().append(cateTwoList);
			 $("#sourceTwo").multiselect('refresh');
			 $("#flowSourceTwo").val('');
			 removeSourceThree();
           }else{
		   	  alert("error!");
		   }
        }
   	  });
     }else{
	 	 removeSourceTwo();
	  }
}

function changeSourceThree(source1,source2){
	var strSource1 = String(source1);
	var strSource2 = String(source2);
	
	if(strSource1 != "" && source2 != ""){
      	jQuery.ajax({
       		type:"post",
        	dataType:"json",
        	async:true,
        	url:"/irtools/flowsourcesearch",
        	data:{"source1":strSource1,"source2":strSource2},
        	success:function(data){
           	if(data!="" && data.result =="right"){
              	var cateThreeList = "";
              	$.each(data.flowSourceListThree, function(i, obj) {
              		cateThreeList = cateThreeList + "<option value='"+obj.source3+"' title='"+obj.source3_name+"'>"+obj.source3_name+"</option>";
              	});
             	$("#sourceThree").empty().append(cateThreeList);
			 	$("#sourceThree").multiselect('refresh');
			 	$("#flowSourceThree").val('');
           	}else{
		   	  	alert("error!");
		   	}
        }
   	  });
     }else{
		removeSourceThree();
	 }
}


$(function(){
   	$("#sourceThree").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			if($("input[name='multiselect_#sourceThree']:checkbox:checked").length == 0){
				$("#flowSourceThree").val('');
			}   		
   		},
   		checkAll: function(){},
		uncheckAll: function(){
            $("#flowSourceThree").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var three='';
            var idcs=checkedItems.map(function(element){
            	three = element.title;
            	return "'"+element.value+"'"; 
            }).join(',');
              $("#flowSourceThree").val(idcs);
             if(numChecked == numTotal){
                     ("#flowSourceThree").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? three : numChecked + ' of ' + numTotal + ' types';
		}
   });
});



$(function(){
   	$("#sourceTwo").multiselect({
		height:300,
		minWidth:140,
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			var checkedItems=$("input[name='multiselect_sourceTwo']:checkbox:checked");
			if(checkedItems.length == 0){
				removeSourceThree();
				 $("#flowSourceTwo").val('');
			}else if(checkedItems.length == 1){
				changeSourceThree($("#sourceOne").val(),checkedItems.get(0).value);
			}
   		},
   		checkAll: function(){
			var checkedItems=$("input[name='multiselect_sourceTwo']:checkbox:checked");
			if(checkedItems.length == 1){
				changeSourceThree($("#sourceOne").val(),checkedItems.get(0).value);
			}   			
   		},
		uncheckAll: function(){
			removeSourceThree();
            $("#flowSourceTwo").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var two='';
            var idcs=checkedItems.map(function(element){
            		two = element.title;
            	return "'"+element.value+"'"; 
            }).join(',');
            if(numChecked > 1){
            	removeSourceThree();
            }
             $("#flowSourceTwo").val(idcs);
             if(numChecked == numTotal  && numTotal > 1){
                     $("#flowSourceTwo").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? two : numChecked + ' of ' + numTotal + ' types';
		}
   });
});

$(function(){
   	$("#sourceOne").multiselect({
		height:300,
		minWidth:140,	
		noneSelectedText: "全部",
		checkAllText: "全选",
		uncheckAllText: '清空',
		click: function(event, ui){
			var checkedItems=$("input[name='multiselect_sourceOne']:checkbox:checked");
			if(checkedItems.length == 0){
				$("#flowSourceOne").val('');
				removeSourceTwo();
			}else if(checkedItems.length == 1){
				changeSourceTwo(checkedItems.get(0).value);
			}
   		},
   		checkAll: function(){
   			var checkedItems=$("input[name='multiselect_sourceOne']:checkbox:checked");
   			if(checkedItems.length == 1){
				changeSourceTwo(checkedItems.get(0).value);
			}
   		},
		uncheckAll: function(){
			removeSourceTwo();
            $("#flowSourceOne").val('');
	 	},
		selectedText: function(numChecked, numTotal, checkedItems){
			var one='';
            var idcs=$.map(checkedItems,function(element){
            	one = element.title;
            	return "'"+element.value+"'"; 
            }).join(',');
            if(numChecked > 1){
            	removeSourceTwo();
            }
            $("#flowSourceOne").val(idcs);
            if(numChecked == numTotal  && numTotal > 1){
                     $("#flowSourceOne").val('');
                     return "全部";
             }
			return (numChecked <= 1) ? one : numChecked + ' of ' + numTotal + ' types';
		}
   });
});

$(function(){
	$('div.multiSel').each(function(){
			var hiddenInput = $(this).children("input:hidden");
			var name= hiddenInput.attr('name');
			var select = $(this).children("select");
			
			$(select).multiselect({
 					height:235,
					minWidth:145,			  
					noneSelectedText: "全部",
					checkAllText: "全选",
					uncheckAllText: '清空',
					click: function(event, ui){
						var checkedItems=$("input[name='multiselect_"+name+"_multi']:checkbox:checked");
						if(checkedItems.length == 0){
							$("#"+name).val('');
						}	
   					},
   					checkAll: function(){},
					uncheckAll: function(){
            			$("#"+name).val('');
	 				},
					selectedText: function(numChecked, numTotal, checkedItems){
						var one='';
            			var idcs=$.map(checkedItems,function(element){
            				one = element.title;
            				return "'"+element.value+"'"; 
            			}).join(',');
            			$("#"+name).val(idcs);
            			if(numChecked == numTotal  && numTotal > 1){
                  	  	 	$("#"+name).val('');
                     		return "全部";
             			}
						return (numChecked <= 1) ? one : numChecked + ' of ' + numTotal + ' types';
					}
   			});
		});
});


function getCheckedValue(elementID){
	var str_checked_values = $(elementID).multiselect("getChecked").map(function(){
   		return this.value;    
	}).get().join(',');
	return str_checked_values;
}

function removeCate(level,IDSuffix){
	if(level <= 3){
		$("#cateThree_"+IDSuffix).empty().multiselect('refresh');
		$("#"+IDSuffix+"NewCateThree").val('');
	}
	if(level <= 2){
		  $("#cateTwo_"+IDSuffix).empty().multiselect('refresh');
		  $("#"+IDSuffix+"NewCateTwo").val('');
	}
	if(level <= 1){
		  $("#cateOne_"+IDSuffix).empty().multiselect('refresh');
		  $("#"+IDSuffix+"NewCateOne").val('');
	}
}

function getOptionList(dataList,type){
	var optionList='';
	$.each(dataList, function(i, obj) {
		  if(type == 1){
		  	optionList = optionList + "<option value='"+obj.cate1_name+"' title='"+obj.cate1_name+"'>"+obj.cate1_name+"</option>";
		  }else if(type == 2){
		  	optionList = optionList + "<option value='"+obj.cate2_name+"' title='"+obj.cate2_name+"'>"+obj.cate2_name+"</option>";
		  }else if(type == 3){
		  	optionList = optionList + "<option value='"+obj.cate3_name+"' title='"+obj.cate3_name+"'>"+obj.cate3_name+"</option>";
		  }
          
     });
    return optionList;      
}

function changeCate(level,type,businessType,cate1,cate2){
	var reqUrl = '';
	var IDSuffix = 'dp';
	var paramData='';
	if(type == "dp")
		reqUrl = "/irtools/newdiscate";
	else if(type == "bc"){
		reqUrl = "/irtools/newbelongcate";
		IDSuffix="bc";
	}
	var isBiz = $("#isBiz").val();
	if(level == 3){
		paramData = {"cate1":String(cate1),"cate2":String(cate2),"business_type_name":String(businessType),"isBiz":String(isBiz)};
	}else if(level == 2){
		paramData = {"cate1":String(cate1),"business_type_name":String(businessType),"isBiz":String(isBiz)};
	}else if(level == 1){
		paramData = {"business_type_name":String(businessType),"isBiz":String(isBiz)};
	}
	
      	jQuery.ajax({
      		type:"POST",
        	dataType:"json",
        	async:true,
        	url:reqUrl,
        	data:paramData,
        	success:function(data){
          	if(data!="" && data.result =="right"){
          		var cateList='';
				if(level == 3){
					if(type == "dp")
						cateList = getOptionList(data.disCateListThree,3);
					else if(type == "bc")
						cateList = getOptionList(data.belongCateListThree,3);
					$("#cateThree_"+IDSuffix).empty().append(cateList).multiselect('refresh');
				}else if(level == 2){
					if(type == "dp")
						cateList = getOptionList(data.disCateListTwo,2);
					else if(type == "bc")
						cateList = getOptionList(data.belongCateListTwo,2);
					$("#cateTwo_"+IDSuffix).empty().append(cateList).multiselect('refresh');
					removeCate(3,IDSuffix);
				}else if(level == 1){
					if(type == "dp")
						cateList = getOptionList(data.disCateListOne,1);
					else if(type == "bc")
						cateList = getOptionList(data.belongCateListOne,1);
					$("#cateOne_"+IDSuffix).empty().append(cateList);
					$("#cateOne_"+IDSuffix).multiselect('refresh');
					removeCate(2,IDSuffix);
				}
           }else{
		   	  alert("error!");
		   }
        }
   	  });
}


$(function(){
	$.each($("div[type='cate']").get().reverse(),function(i,obj){
			var hiddenInput = $(obj).children("input:hidden");
			var name= hiddenInput.attr('name');
			var select = $(obj).children("select");
			var selectType=$(select).attr('type');
			var selectName=$(select).attr('name');
			var selectLevel=parseInt($(select).attr('level'));
			$(select).multiselect({
					height:300,
					minWidth:140,
					noneSelectedText: "全部",
					checkAllText: "全选",
					uncheckAllText: '清空',
					click: function(event, ui){
						var checkedItems=$("input[name='multiselect_"+selectName+"']:checkbox:checked");
						if(checkedItems.length == 0){
							removeCate(selectLevel+1,selectType);
							$("#"+name).val('');
						}else if(checkedItems.length == 1){
							if(selectLevel == 0)
								changeCate(1,selectType,checkedItems.get(0).value);
							else if(selectLevel == 1){
								var busName = getCheckedValue("#businessTypeName_"+selectType);
								changeCate(2,selectType,busName,checkedItems.get(0).value);
							}else if(selectLevel == 2){
								var busName = getCheckedValue("#businessTypeName_"+selectType);
								var cate1 = getCheckedValue("#cateOne_"+selectType);
								changeCate(3,selectType,busName,cate1,checkedItems.get(0).value);
							}
						}	
   					},
   					checkAll: function(){
   						var checkedItems=$("input[name='multiselect_"+selectName+"']:checkbox:checked");
   						if(checkedItems.length == 1){
							if(selectLevel == 1){
								var busName = getCheckedValue("#businessTypeName_"+selectType);
								changeCate(2,selectType,busName,checkedItems.get(0).value);
							}else if(selectLevel == 2){
								var busName = getCheckedValue("#businessTypeName_"+selectType);
								var cate1 = getCheckedValue("#cateOne_"+selectType);
								changeCate(3,selectType,busName,cate1,checkedItems.get(0).value);
							}
						}	
   					},
					uncheckAll: function(){
						if($("input[name='multiselect_"+selectName+"']:checkbox").is(':disabled')){
							return;
						}
						removeCate(selectLevel+1,selectType);
            			$("#"+name).val('');
	 				},
					selectedText: function(numChecked, numTotal, checkedItems){
						var one='';
            			var idcs=$.map(checkedItems,function(element){
            				one = element.title;
            				return "'"+element.value+"'"; 
            			}).join(',');
            			if(numChecked > 1){
            				removeCate(selectLevel+1,selectType);
            			}
            			$("#"+name).val(idcs);
            			if(numChecked == numTotal  && numTotal > 1){
                  	  	 	$("#"+name).val('');
                     		return "全部";
             			}
						return (numChecked <= 1) ? one : numChecked + ' of ' + numTotal + ' types';
					}
			});
	});
});